<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 2017/7/6
 * Time: 上午9:48
 */
class TransController extends AdminBaseController
{
    public function index()
    {
        $this->setTitle('转生任务时长');

        $filter = new PubFilter();
        $chart = new PubChart();
        $grid = new PubGrid();

        $filter->addOsFilter()
            ->addServerFilter(true)
            ->addFilter('time', 'input', PubFunc::t('时间'), array('date' => 'day', 'value' => date('Y-m-d', strtotime('-1 day'))))
            ->addExport();

        $params = $filter->get();

        $header = TransService::indexHeader($params['type']);
        $data = TransService::indexData($params);

        if ($filter->isExport()) {
            $filename = LibExcel::getFilename('转生任务时长', $params);
            LibExcel::exportCsv($header, $data, $filename);
        } else {
            $grid->addGrid($header, $data, array(
                'order' => array('RecDate', 'desc')
            ));

            $this->out['filter'] = $filter->show();
            $this->out['chart'] = $chart->show();
            $this->out['grid'] = $grid->show();
        }
    }
}